﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ReadWriteCsv;
using System.Text.RegularExpressions;

namespace StockAnomalyDetector
{
    class FoxTail : Pattern
    {
        private readonly int lastTenMin;
        private double minPrice;
        private double  maxPrice;

        public static List<string> exceptionList = new List<string>() { "stockCode,date,0,1" };
        public static CsvFileWriter writer = new CsvFileWriter(@"D:\股票数据\" + "FoxTail" + ".csv");

        public FoxTail(CsvRow r) : base(r)
        {
            lastTenMin = 145000;
            minPrice = 6666666;
            maxPrice = -1;
        }

        public override void Analyze()
        {
            ParseRow();
            if (time > lastTenMin)
            {
                if (price > maxPrice)
                    maxPrice = price;
                if (price < minPrice)
                    minPrice = price;
            }
        }

        public override void End(string sourceName)
        {
            if ((maxPrice - minPrice) / minPrice > 0.033)
            {
                Record record = new Record
                {
                    stockcode = Convert.ToString(Regex.Match(sourceName, @"[A-Z]{2}\d{6}")),
                    date = Convert.ToString(Regex.Match(sourceName, @"\d{8}")),
                    startTime = 0,
                    endTime = 0
                };
                Console.WriteLine("FoxTail： "+record);
                exceptionList.Add(record.ToString());
            }
        }
    }
}
